<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>

<link rel="stylesheet" type="text/css" href="<?php echo theme_url('css/common.css');?>" />
<link rel="stylesheet" type="text/css" href="<?php echo asset_url('js/bootstrap/css/bootstrap.min.css');?>" />
<link rel="stylesheet" type="text/css" href="<?php echo asset_url('js/bootstrap/css/bootstrap-responsive.min.css');?>" />

<script type="text/javascript" src="<?php echo asset_url('js/jquery/jquery.js');?>"></script>

<link rel="stylesheet" type="text/css" href="<?php echo theme_url('css/goods.css');?>" />
<script type="text/javascript" src="<?php echo theme_url('js/goods.js');?>"></script>

<!-- swfupload 上传插件 -->
<link rel="stylesheet" type="text/css" href="<?php echo asset_url('js/swfupload/jquery.swfupload.css');?>" />
<script type="text/javascript" src="<?php echo asset_url('js/swfupload/swfupload.js');?>"></script>
<script type="text/javascript" src="<?php echo asset_url('js/swfupload/swfupload.queue.js');?>"></script>
<script type="text/javascript" src="<?php echo asset_url('js/swfupload/jquery.swfupload.js');?>"></script>

<!-- jquery ui 插件 -->
<script type="text/javascript" src="<?php echo asset_url('js/jquery/ui/jquery-ui.custom.js');?>"></script>

<!-- jquery ajaxfileupload 上传插件 -->
<link rel="stylesheet" type="text/css" href="<?php echo asset_url('js/ajaxfileupload/jquery.ajaxfileupload.css');?>" />
<script type="text/javascript" src="<?php echo asset_url('js/ajaxfileupload/ajaxfileupload.js');?>"></script>
<script type="text/javascript" src="<?php echo asset_url('js/ajaxfileupload/jquery.ajaxfileupload.js');?>"></script>

<script type="text/javascript">

	$(document).ready(function(){
		
		//图片上传
		var swf = new SWFUpload({
			'upload_url': "<?php echo admin_url('goods/upload');?>",
			'post_params': {"PHPSESSID": "<?php echo session_id();?>"},
			'file_size_limit': '2MB',
			'file_upload_limit': 100,
			'file_queue_limit': 10,
			'file_types': "*.jpg;*.jpeg;*.png;*.gif",
			'file_types_description': "JPG Images;JPEG Images;PNG Images;GIF Images;",
			'button_placeholder_id': 'upload',
			'button_text': '选择文件',
			'button_width': 50,
			'button_height': 20,
			'file_queued_handler': goods_file_queued_handler,
			'file_queue_error_handler': goods_file_queue_error_handler,
			'file_dialog_complete_handler': goods_file_dialog_complete_handler,
			'upload_start_handler': goods_upload_start_handler,
			'upload_progress_handler': goods_upload_progress_handler,
			'upload_success_handler': goods_upload_success_handler,
			'upload_error_handler': goods_upload_error_handler,
			'upload_complete_handler': goods_upload_complete_handler
		});

		//显示图片
		<?php foreach ($picture_list as $row) {?>
			show_img("<?php echo $row['url'];?>", <?php echo $row['order'];?>);
		<?php }?>

		$('#picture_box').sortable({
			revert: true,
			cursor: 'move',
			opacity: 0.5
		});

		$('#upload_pic').ajaxfileupload({
			url: '<?php echo admin_url('goods/upload');?>',
			name: 'Filedata',
			success: function(data) {
				if (data.code > 0) {
					alert(data.msg);
				} else {
					$(':input[name="pic"]').val(data.msg);
					if ($('#upload_pic').nextAll('img').size() > 0) {
						$('#upload_pic').nextAll('img').first().attr('src', data.msg);
					} else {
						$('#upload_pic').after('<br /><img src="' + data.msg + '" width="100" height="100" />');
					}
				}
			},
			error: function() {
				alert('error');
			}
		});
		
	});
</script>

</head>
<body>

	<?php echo widget('admin/header');?>

	<div id="wrap" class="container">

		<form class="form-horizontal" action="__SELF__" method="post" enctype="multipart/form-data">

			<div class="btn-toolbar">
				<div class="btn-group">
					<a href="<?php echo $this->session->get('back');?>" class="btn">返回</a>
				</div>
				<div class="btn-group">
					<button type="submit" class="btn btn-primary">提交更改</button>
				</div>
				<div class="btn-group">
					<button type="reset" class="btn">取消</button>
				</div>
			</div>

			<input type="hidden" name="id" value="<?php echo $data['id'];?>" />

			<ul class="nav nav-tabs">
				<li class="active"><a href="#tab-1" data-toggle="tab">基本信息</a></li>
				<li><a href="#tab-2" data-toggle="tab">内容</a></li>
				<li><a href="#tab-3" data-toggle="tab">图片</a></li>
				<li><a href="#tab-4" data-toggle="tab">规格</a></li>
				<li><a href="#tab-5" data-toggle="tab">相关产品</a></li>
			</ul>

			<div class="tab-content">
				<!-- 基本信息 -->
				<div id="tab-1" class="tab-pane active">

					<div class="control-group">
						<label class="control-label" for="name">名称：</label>
						<div class="controls">
							<input type="text" name="name" value="<?php echo $data['name'];?>" class="span4" id="name">
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="category_id">分类：</label>
						<div class="controls">
							<select name="category_id">
								<option value="0">请选择</option>
								<?php foreach ($category_list as $row) {?>
								<option value="<?php echo $row['id'];?>" <?php echo $data['category_id'] == $row['id'] ? 'selected="selected"' : '';?>><?php echo str_repeat('___', $row['level'] - 1).$row['name'];?></option>
								<?php }?>
							</select>
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="supplier_id">供应商：</label>
						<div class="controls">
							<select name="supplier_id" class="text">
								<option value="0">请选择</option>
								<?php foreach ($supplier_list as $row) {?>
								<option value="<?php echo $row['id'];?>" <?php echo $row['id'] == $data['supplier_id'] ? 'selected="selected"' : '';?>><?php echo $row['name'];?></option>
								<?php }?>
							</select>
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="sku">货号：</label>
						<div class="controls">
							<input type="text" name="sku" value="<?php echo $data['sku'];?>" class="span3" id="sku">
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="weiget">重量：</label>
						<div class="controls">
							<input type="text" name="weiget" value="<?php echo $data['weight'];?>" class="span1" id="weiget"> 克
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="market_price">市场价：</label>
						<div class="controls">
							<input type="text" name="market_price" value="<?php echo $data['market_price'];?>" class="span1" id="market_price"> 元
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="sale_price">销售价：</label>
						<div class="controls">
							<input type="text" name="sale_price" value="<?php echo $data['sale_price'];?>" class="span1" id="sale_price"> 元
						</div>
					</div>

					<div class="control-group">
						<label class="control-label">销售状态：</label>
						<div class="controls">
							<label class="radio">
								<input type="radio" name="on_sale" id="on_sale_yes" value="1" <?php echo $data['on_sale'] == 1 ? 'checked="checked"' : '';?>>
								上架
							</label>
							<label class="radio">
								<input type="radio" name="on_sale" id="on_sale_yes" value="0" <?php echo $data['on_sale'] == 0 ? 'checked="checked"' : '';?>>
								下架
							</label>
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="stock">库存：</label>
						<div class="controls">
							<input type="text" name="stock" value="<?php echo $data['stock'];?>" class="span1" id="stock"> 件
						</div>
					</div>

					<div class="control-group">
						<label class="control-label">图片：</label>
						<div class="controls">
							<input type="text" name="pic" value="<?php echo $data['pic'];?>" class="span3" />
							<span id="upload_pic" class="btn">选择图片</span>
							<?php if ($data['pic']) {?>
							<br /><img src="<?php echo $data['pic'];?>" width="100" height="100" />
							<?php }?>
						</div>
					</div>

				</div>

				<!-- 内容 -->
				<div id="tab-2" class="tab-pane">

					<div class="control-group">
						<label class="control-label" for="title">标题：</label>
						<div class="controls">
							<input type="text" name="title" value="<?php echo $data['title'];?>" class="span4" id="title">
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="keywords">关键词：</label>
						<div class="controls">
							<input type="text" name="keywords" value="<?php echo $data['keywords'];?>" class="span4" id="keywords">
						</div>
					</div>

					<div class="control-group">
						<label class="control-label" for="description">描述：</label>
						<div class="controls">
							<textarea name="description" class="span4" rows="4" id="description"><?php echo $data['description']?></textarea>
						</div>
					</div>

					<div class="control-group">
						<label class="control-label">内容：</label>
						<div class="controls">
							<?php echo editor('content', $data['content'], 800, 400);?>
						</div>
					</div>

				</div>

				<!-- 图片 -->
				<div id="tab-3" class="tab-pane">
					<table class="form">
						<tr>
							<td colspan="2">
								<div class="jquery-swfupload">
									<spqn id="upload"></span>
								</div>
							</td>
						</tr>
						<tr>
							<td colspan="2">
								<ul id="picture_box" class="unstyled"></ul>
							</td>
						</tr>
					</table>
				</div>

				<!-- 规格 -->
				<div id="tab-4" class="tab-pane">
					<table class="form">
						<tr>
							<td colspan="2"><input type="button" value="增加规格" class="btn" id="add_sku"/></td>
						</tr>
					</table>
				</div>

				<!-- 相关商品 -->
				<div id="tab-5" class="tab-pane">
					<table class="form">
						<tr>
							<td colspan="2"><input type="button" value="添加" class="btn" id="add_related"/></td>
						</tr>
					</table>
				</div>

				<div class="form-actions">
					<button type="submit" class="btn btn-primary">提交更改</button>
					<button type="reset" class="btn">取消</button>
				</div>

			</div>

		</form>
	</div>

	<?php echo widget('admin/footer');?>

</body>
</html>